package edu.mse.camel.client.whiteboard.diagram.custom;

import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.Shape;
import org.eclipse.draw2d.geometry.Rectangle;

/*
 * 
 * The code for cylinder is retrieve from 
 * org.eclipse.gmf.runtime.diagram.ui.geoshapes.internal.draw2d.figures.GeoShapeCylinderFigure
 * written by jschofie. 
 * 
 */
public class Cylinder extends Shape{

	@Override
	public void paintFigure(Graphics graphics) {
		
		Rectangle r = getBounds();
		int height = (int) (r.height * 0.25);
		
		Rectangle ellipse = new Rectangle(r.x, r.y, r.width, height);
		Rectangle middle = new Rectangle(r.x, r.y+(height/2), r.width, r.height-height+1);
		Rectangle lowerArc = new Rectangle(r.x, r.y+r.height-height-1, r.width, height);
		
		// Draw the ellipse with the fill color
		graphics.fillOval( ellipse );

		// Draw the middle section with the fill color
		graphics.fillRectangle( middle );
		
		// Draw the lower arc with the fill color
		graphics.fillArc( lowerArc, 180, 180 );
	
		// Draw the ellipse outline
		graphics.drawOval( ellipse.x, ellipse.y, ellipse.width - 1, ellipse.height - 1 );
		
		// Draw the middle section
		graphics.drawLine( middle.x, middle.y, middle.x, middle.y + middle.height );
		graphics.drawLine( middle.x + middle.width - 1, middle.y, middle.x + middle.width - 1, middle.y + middle.height );
		
		// Draw the lower arc outline
		graphics.drawArc( lowerArc, 180, 180 );
	}

	@Override
	protected void fillShape(Graphics graphics) {
		
	}

	@Override
	protected void outlineShape(Graphics graphics) {
		
	}
}
